<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>提现申请列表</title>
    <link href="../../resource/css/bootstrap.min.css?v=3.3.5" rel="stylesheet"
          th:href="@{/resource/css/bootstrap.min.css?v=3.3.5}"/>
    <link href="../../resource/css/font-awesome.min.css?v=4.4.0" rel="stylesheet"
          th:href="@{/resource/css/font-awesome.min.css?v=4.4.0}"/>
    <!-- Morris -->
    <link href="../../resource/css/animate.min.css" rel="stylesheet" th:href="@{/resource/css/animate.min.css}"/>

    <link href="../../resource/css/style.min.css?v=4.0.0" rel="stylesheet"
          th:href="@{/resource/css/style.min.css?v=4.0.0}"/>
    <link href="../../resource/hotui/css/hotui.style.override.css"
          th:href="@{/resource/hotui/css/hotui.style.override.css}" rel="stylesheet"/>
    <link href="../../resource/css/style-diy.css?v=4.0.0" rel="stylesheet"
          th:href="@{/resource/css/style-diy.css?v=4.0.0}"/>
    <link href="../../resource/hotui/js/plugins/datetimepick/css/daterangepicker.css"
          th:href="@{/resource/hotui/js/plugins/datetimepick/css/daterangepicker.css}" rel="stylesheet"/>
</head>
<body class="gray-bg">
<div class="wrapper wrapper-content animated fadeInRight">
    <!--search-->
    <form role="form" id="searchForm" class="search-panel" method="get" th:object="${condition}">
        <div class="row">
            <div class="col-lg-12">
                <div class="ibox">
                    <div class="ibox-content">
                        <div class="form-inline">
                            <input type="hidden" th:value="${pageIndex}" name="pageIndex"/>
                            <input type="hidden" th:value="*{withdrawStatus}" name="withdrawStatus"/>
                            <div class="form-inline">
                                <div class="form-group m-r-sm">
                                    <label class="control-label">用户名：</label>
                                    <input type="text" class="form-control input-sm mb10" id="userNo" name="userNo"
                                           th:value="${userNo}"
                                           placeholder="请输入用户名"/>
                                </div>
                                <div class="form-group m-r-sm">
                                    <label class=" control-label" for="createTimePick">申请时间：</label>
                                    <input readonly type="text" class="form-control input-sm mb10 data-range-pick"
                                           id="createTimePick" start-element="#beginTime"
                                           end-element="#endTime" placeholder="开始时间-结束时间" style="width: 377px;"/>
                                    <input type="hidden" th:value="*{beginTime}" id="beginTime" name="beginTime"/>
                                    <input type="hidden" th:value="*{endTime}" id="endTime" name="endTime"/>
                                </div>
                                <div class="form-group m-r-sm">
                                    <button type="button" onclick="listHandler.search(1)"
                                            class="btn btn-primary btn-sm m-b-none searchBtn">筛选
                                    </button>
                                    <button type="button" onclick="listHandler.searchAll()"
                                            class="btn btn-primary btn-sm m-b-none">显示全部
                                    </button>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </form>
    <!--search-->


    <!--list-->
    <div class="row">
        <div class="col-lg-12">
            <div class="ibox float-e-margins m-b-none">
                <div class="tabs-container">
                    <ul class="nav nav-tabs">
                        <li class="active" th:class="${condition.withdrawStatus==-1?'active':''}">
                            <a th:if="${withdrwaType==0}" th:href="@{/withdraw/list}" href="#tab-2">全部</a>
                            <a th:if="${withdrwaType==1}" th:href="@{/withdraw/list/type}" href="#tab-2">全部</a>
                        </li>
                        <li th:class="${condition.withdrawStatus==0?'active':''}">
                            <a th:if="${withdrwaType==0}" th:href="@{/withdraw/list(withdrawStatus=0)}">待审核</a>
                            <a th:if="${withdrwaType==1}" th:href="@{/withdraw/list/type(withdrawStatus=0)}">待审核</a>
                        </li>
                        <li th:class="${condition.withdrawStatus==1?'active':''}">
                            <a th:if="${withdrwaType==0}" th:href="@{/withdraw/list(withdrawStatus=1)}">审核通过</a>
                            <a th:if="${withdrwaType==1}" th:href="@{/withdraw/list/type(withdrawStatus=1)}">审核通过</a>
                        </li>
                        <li th:class="${condition.withdrawStatus==2?'active':''}">
                            <a th:if="${withdrwaType==0}" th:href="@{/withdraw/list(withdrawStatus=2)}">审核失败</a>
                            <a th:if="${withdrwaType==1}" th:href="@{/withdraw/list/type(withdrawStatus=2)}">审核失败</a>
                        </li>
                        <li th:class="${condition.withdrawStatus==3?'active':''}">
                            <a th:if="${withdrwaType==0}" th:href="@{/withdraw/list(withdrawStatus=3)}">发放成功</a>
                            <a th:if="${withdrwaType==1}" th:href="@{/withdraw/list/type(withdrawStatus=3)}">发放成功</a>
                        </li>
                        <li th:class="${condition.withdrawStatus==4?'active':''}">
                            <a th:if="${withdrwaType==0}" th:href="@{/withdraw/list(withdrawStatus=4)}">发放失败</a>
                            <a th:if="${withdrwaType==1}" th:href="@{/withdraw/list/type(withdrawStatus=4)}">发放失败</a>
                        </li>
                    </ul>
                    <div class="tab-content">
                        <div class="tab-pane active">
                            <div class="panel-body table-responsive">
                                <table class="table table-bordered table-hover table-center">
                                    <thead>
                                    <tr>
                                        <th style="width: 5%">提现编号</th>
                                        <th style="width: 10%">用户名</th>
                                        <th style="width: 10%">姓名</th>
                                        <th style="width: 15%">银行信息</th>
                                        <th style="width: 15%">银行卡号</th>
                                        <th style="width: 5%">提现金额</th>
                                        <th style="width: 5%">手续费</th>
                                        <th style="width: 5%">打款金额</th>
                                        <th style="width: 10%">申请时间</th>
                                        <th style="width: 10%">提现状态</th>
                                        <th style="width: 150px;">操作</th>
                                    </tr>
                                    </thead>
                                    <tbody>
                                    <tr th:each="apply:${list}">
                                        <td th:text="${apply.applyId}"></td>
                                        <td th:text="${apply.userPo.mobile}"></td>
                                        <td th:text="${apply.realName}"></td>
                                        <td>
                                            <span th:text="${apply.bankName}"></span>
                                            <br/>
                                            <span th:text="${apply.branchBankName}"></span>
                                        </td>
                                        <td th:text="${apply.bankNo}"></td>
                                        <td th:text="${apply.applyMoney}"></td>
                                        <td th:text="${apply.applyFee}"></td>
                                        <td th:text="${apply.applyMoney - apply.applyFee}"></td>
                                        <td th:text="${#temporals.format(apply.createTime,'yyyy-MM-dd HH:mm:ss')}"></td>
                                        <td th:text="${apply.withdrawStatus.desc}"></td>
                                        <td>
                                            <button th:if="${apply.withdrawStatus.code} == 0"
                                                    th:onclick="|listHandler.agree(${apply.applyId},1)|"
                                                    type="button" class="btn btn-info btn-xs m-b-none">通过
                                            </button>
                                            <button th:if="${apply.withdrawStatus.code} == 0"
                                                    th:onclick="|listHandler.changeStatus(${apply.applyId},2)|"
                                                    type="button" class="btn btn-info btn-xs m-b-none">拒绝
                                            </button>
                                            <button th:if="${apply.withdrawStatus.code} == 1"
                                                    th:onclick="|listHandler.agree(${apply.applyId},3)|"
                                                    type="button" class="btn btn-info btn-xs m-b-none">确认发放
                                            </button>
                                            <button th:if="${apply.withdrawStatus.code} == 1"
                                                    th:onclick="|listHandler.changeStatus(${apply.applyId},4)|"
                                                    type="button" class="btn btn-danger btn-xs m-b-none">发放失败
                                            </button>
                                        </td>
                                    </tr>
                                    </tbody>
                                </table>
                                <p style="float: left; margin: 20px 0;">
                                    共<span th:text="${totalRecords}"></span>条记录，当前第<span
                                        th:text="${pageIndex}"></span>/<span
                                        th:text="${totalPages==0?1:totalPages}"></span>，每页20条记录
                                </p>
                                <ul style="float: right;" class="pagination pagination-split">
                                </ul>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>

</div>


<div id="refuse_reason_modal" class="modal-content-tag">
    <form id="modal_form">
        <input name="applyId" id="applyId" type="hidden"/>
        <input name="applyStatus" id="applyStatus" type="hidden"/>
        <div class="form-horizontal" style="width: 479px;">
            <div class="form-group">
                <label class="col-sm-3 control-label">*拒绝原因：</label>
                <div class="col-sm-9">
                    <textarea class="form-control" id="refuse_reason" name="remark" placeholder="请输入拒绝原因"
                              rows="5" style="height: 100px;width: 300px;"></textarea>
                </div>
            </div>
        </div>
    </form>
</div>
<!--基础框架js-->
<script src="../../resource/js/jquery.min.js?v=2.1.4" th:src="@{/resource/js/jquery.min.js?v=2.1.4}"></script>
<script src="../../resource/js/bootstrap.min.js?v=3.3.5" th:src="@{/resource/js/bootstrap.min.js?v=3.3.5}"></script>
<script src="../../resource/hotui/js/hot/bootstrap.hot.extra-utils.js"
        th:src="@{/resource/hotui/js/hot/bootstrap.hot.extra-utils.js}"></script>
<script src="../../resource/hotui/js/hot/bootstrap.hot.extra-init.js"
        th:src="@{/resource/hotui/js/hot/bootstrap.hot.extra-init.js}"
></script>

<script src="../../resource/lib/moment.min.js" th:src="@{/resource/lib/moment.min.js}"></script>
<script src="../../resource/hotui/js/plugins/datetimepick/js/daterangepicker.js"
        th:src="@{/resource/hotui/js/plugins/datetimepick/js/daterangepicker.js}"></script>

<script type="text/javascript" th:inline="javascript">
    const pageIndex = /*[[${pageIndex}]]*/  1;
    const totalPages = /*[[${totalPages}]]*/  1;
    const pageUri = /*[[@{/withdraw/list}]]*/  "";
    const updateStatusUri = /*[[@{/withdraw/updateStatus}]]*/  "";
    const withdrwaType = /*[[${withdrwaType}]]*/  0;

</script>
<script>
    let checkModal = $("#refuse_reason_modal").modal("拒绝/失败原因", function () {
        let applyId = $("#applyId").val();
        let applyStatus = $("#applyStatus").val();
        let remark = $("#refuse_reason").val();
        listHandler.check(applyId, applyStatus, remark);
    });


    $(function () {
        //初始化分页
        var pageinate = new hot.paging(".pagination", pageIndex, totalPages, 7);

        pageinate.init(function (p) {
            listHandler.search(p);
        });
        $(document).keyup(function (event) {
            if (event.keyCode === 13) {
                $(".searchBtn").trigger("click");
            }
        });
    });
    let listHandler = {
        search: function (pageIndex) {
            $("input[name=pageIndex]").val(pageIndex);
            $("#searchForm").submit();
        },
        searchAll: function () {
            if (withdrwaType === 1) {
                window.location.href = pageUri + "/type";
            } else {
                window.location.href = pageUri;
            }
        },
        changeStatus: function (applyId, applyStatus) {
            checkModal.show(function () {
                $('#applyId').val(applyId);
                $('#applyStatus').val(applyStatus);
            });
        },
        check: function (applyId, applyStatus, remark) {
            layer.load();
            $.ajax(updateStatusUri, {
                method: 'POST',
                data: {
                    applyId: applyId,
                    withdrawStatus: applyStatus,
                    refuseReason: remark
                },
                success: function (apiResult) {
                    if (apiResult.resultCode === 2000) {
                        checkModal.hide(function () {
                            layer.close();
                            hot.tip.success("操作成功");
                            $("#searchForm").submit();
                        });
                    } else {
                        hot.tip.error("操作失败--" + apiResult.resultMsg);
                    }
                }
            });
        },
        agree: function (applyId, applyStatus) {
            hot.confirm("确定执行此操作？", function () {
                layer.load();
                $.ajax(updateStatusUri, {
                    method: 'POST',
                    data: {
                        applyId: applyId,
                        withdrawStatus: applyStatus,
                        refuseReason: ''
                    },
                    success: function (apiResult) {
                        if (apiResult.resultCode === 2000) {
                            layer.close();
                            checkModal.hide(function () {
                                hot.tip.success("操作成功");
                                $("#searchForm").submit();
                            });
                        } else {
                            hot.tip.error("操作失败--" + apiResult.resultMsg);
                        }
                    }
                });
            });
        },
    }
</script>
</body>
</html>